package reduce.fz.com.reduce.util;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

/**
 * Created by qingshengzheng on 15/10/21.
 */
public class InputMethodUtil {

    /**
     * 视图获取焦点并且弹出输入框
     *
     * @param view
     */
    public static void reuestFocus(View view) {
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.requestFocus();
    }

    public static void reuestFocusAndShowInput(View view) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.requestFocus();
        imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    }

    /**
     * 清除焦点
     * @param view
     */
    public static void clearFocus(View view) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        view.clearFocus();
        view.setFocusable(false);
        imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
    }
}
